<template>
  <div>
    <!--表格内容显示区-->
    <el-table
      :data="userList"
      border
      max-height="400"
      style="width: 100%">
      <el-table-column
        prop="id"
        fixed="left"
        align="center"
        header-align="center"
        label="工号"
        width="50">
      </el-table-column>
      <el-table-column
        prop="username"
        fixed="left"
        header-align="center"
        align="center"
        label="姓名"
        width="120">
      </el-table-column>
      <el-table-column
        prop="sex"
        header-align="center"
        align="center"
        label="性别"
        width="60">
        <template slot-scope="scope">
          {{scope.row.sex===0?'男':(scope.row.sex===1)?'女':'保密'}}
        </template>
      </el-table-column>
      <el-table-column
        prop="deptName"
        header-align="center"
        align="center"
        label="职务"
        width="150">
      </el-table-column>
      <el-table-column
        prop=""
        header-align="center"
        align="center"
        label="职级别"
        width="150">
        <template slot-scope="scope">
          <span v-if="scope.row.sex===0">科级</span>
          <span v-if="scope.row.sex===1">副处</span>
          <span v-if="scope.row.sex===2">局级</span>
        </template>
      </el-table-column>
      <el-table-column
        sortable=""
        prop="birth"
        header-align="center"
        align="center"
        label="生日"
        width="150">
        <template slot-scope="scope">
          {{scope.row.birth}}
        </template>
      </el-table-column>
      <el-table-column
        prop=""
        header-align="center"
        align="center"
        label="籍贯"
        width="80">
        <template slot-scope="scope">
          重庆
        </template>
      </el-table-column>
      <el-table-column
        prop="phoneNumber"
        header-align="center"
        align="center"
        label="电话号码"
        width="150">
      </el-table-column>
      <el-table-column
        prop="status"
        label="是否党员"
        header-align="center"
        align="center"
        width="80">
        <template slot-scope="scope">
          <span v-if="scope.row.status===0">是</span>
          <span v-if="scope.row.status===1">不是</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="status"
        label="学位"
        header-align="center"
        align="center"
        width="80">
        <template slot-scope="scope">
          <span v-if="scope.row.sex===0">专科</span>
          <span v-if="scope.row.sex===1">本科</span>
          <span v-if="scope.row.sex===2">硕士</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        header-align="center"
        align="center"
        fixed="right"
        width="180">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" icon="el-icon-edit"
                     @click="openUpdate(scope.row)"></el-button>
          <el-button type="danger" size="mini" icon="el-icon-delete"
                    ></el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--分页-->
    <el-pagination
      style="padding-top: 15px"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="current"
      :page-sizes="[6, 10, 20, 30]"
      :page-size="size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>


  </div>
</template>

<script>
  import { findUserList } from '../../api/system/users'
  import S4_1 from './S4_1'

  export default {
    name: 'S4',
    components: {
      S4_1
    },
    data () {
      return {
        userList: [],
        size: 6,
        total: 100,
        current: 1,
        userVo: {
          roleId: '',
          departmentId: '',
          username: '',
          email: '',
          sex: '',
          nickname: ''
        },
        open: false,
        form: {},
      }
    },
    created () {
      this.getUserList()
    },
    methods: {
      //当每页条数改变
      handleSizeChange (val) {
        this.size = val
        this.getUserList()
      },

      //当前页码改变
      handleCurrentChange (val) {
        this.current = val
        this.getUserList()
      },
      //获得当前页面数据
      async getUserList () {
        findUserList(this.current, this.size, this.userVo).then(res => {
          if (res) {
            this.userList = res.data.data.records
            this.total = res.data.data.total
          }
        })
      },
      openUpdate (row) {
        this.form = JSON.parse(JSON.stringify(row))
        this.$router.push({ path: '/s4_1' ,query:{id:this.form}})
      },
      //关闭弹出框
      closeAddDialog () {
        this.resetForm('form')
        this.form = {}
        this.open = false
      },
    }
  }
</script>

<style scoped>

</style>
